package mario;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public class BackGround {
    //当前是第几关
    private int sort;
    //当前场景的背景
    private BufferedImage bg = null;
    //存放所有障碍物
    private List<Obstacle> obstacles = new ArrayList<>();
    //存放敌人
    private List<Enemy> enemyList = new ArrayList<>();
    //存放死亡的敌人
    private List<Enemy> deadEnemy = new ArrayList<>();
    //存放消灭的场景
    private List<Obstacle> deadObstacles = new ArrayList<>();

    public BackGround(int sort) {
        this.sort = sort;
        if (sort == 1){
            bg = StaticValue.bg1;
            //绘制地面
            for (int i = 0; i < 30; i+=1) {
                //if (i % 3 == 0) continue;
                obstacles.add(new Obstacle(i*30,540,9,this));
            }
            for (int i = 0; i < 30; i+=1) {
                //if (i % 3 == 0) continue;
                obstacles.add(new Obstacle(i*30,570,10,this));
            }

            /*for (int i = 0; i < 15; i++) {
                obstacles.add(new Obstacle(i*60,540,1,this));
            }*/
            //绘制砖块
            obstacles.add(new Obstacle(240,460,2,this));
            obstacles.add(new Obstacle(60,420,2,this));
            obstacles.add(new Obstacle(90,480,2,this));
            obstacles.add(new Obstacle(60,510,2,this));
            //obstacles.add(new Obstacle(120,480,2,this));
            obstacles.add(new Obstacle(120,450,2,this));
            obstacles.add(new Obstacle(90,360,2,this));
            obstacles.add(new Obstacle(130,360,0,this));
            obstacles.add(new Obstacle(190,360,2,this));
            obstacles.add(new Obstacle(250,360,2,this));
            //obstacles.add(new Obstacle(250,220,2,this));
            obstacles.add(new Obstacle(310,360,0,this));
            obstacles.add(new Obstacle(340,390,2,this));
            obstacles.add(new Obstacle(290,420,2,this));
            obstacles.add(new Obstacle(310,220,0,this));
            obstacles.add(new Obstacle(370,360,2,this));
            obstacles.add(new Obstacle(430,360,0,this));
            obstacles.add(new Obstacle(430,220,0,this));
            obstacles.add(new Obstacle(470,300,0,this));
            obstacles.add(new Obstacle(470,420,2,this));
            //obstacles.add(new Obstacle(650,360,0,this));
            //obstacles.add(new Obstacle(770,360,0,this));

            //放怪的层
            obstacles.add(new Obstacle(210,300,0,this));
            for (int i = 240;i < 420;i += 30){
                obstacles.add(new Obstacle(i,300,2,this));
            }
            obstacles.add(new Obstacle(240,270,2,this));
            obstacles.add(new Obstacle(390,270,2,this));
            //火山形
            int k = 1;
            int h = 0;
            for (int i = 560;i < 710;i += 30){
                k+=1;
                //if (i==710 || i==740) continue;
                for (int j = 210;j < 450-30*k;j += 30){
                    obstacles.add(new Obstacle(i,j+30*k,2,this));
                }
                obstacles.add(new Obstacle(i,150+h,0,this));
                h+=30;
            }
            obstacles.add(new Obstacle(710,150+h,0,this));
            k = 2;
            h = 0;
            for (int i = 860;i > 740;i -= 30){
                k+=1;
                //if (i==710 || i==740) continue;
                for (int j = 210;j < 450-30*k;j += 30){
                    obstacles.add(new Obstacle(i,j+30*k,2,this));
                }
                obstacles.add(new Obstacle(i,180+h,0,this));
                h+=30;
            }
            obstacles.add(new Obstacle(740,180+h,0,this));
            obstacles.add(new Obstacle(500,450,2,this));

            //绘制管道
            for (int i = 0; i < 4; i++) {
                obstacles.add(new Obstacle(170+180*i,570,8,this));
                obstacles.add(new Obstacle(190+180*i,570,7,this));
                obstacles.add(new Obstacle(170+180*i,540,6,this));
                obstacles.add(new Obstacle(190+180*i,540,5,this));
                obstacles.add(new Obstacle(170+180*i,510,6,this));
                obstacles.add(new Obstacle(190+180*i,510,5,this));
            }

            //绘制敌人蘑菇
            for (int i = 0; i < 7; i++) {
                enemyList.add(new Enemy(800-90*i,510,true,1,this));
            }
            enemyList.add(new Enemy(300,270,true,1,this));

            //绘制敌人食人花
            for (int i = 0; i < 4; i++) {
                enemyList.add(new Enemy(180+180*i,510,2,true,490,540,this));
            }



        }else if(sort == 2){
            bg = StaticValue.bg2;
            //绘制地面
            for (int i = 0; i < 30; i+=1) {
                //if (i % 3 == 0) continue;
                obstacles.add(new Obstacle(i*30,540,9,this));
            }
            for (int i = 0; i < 30; i+=1) {
                //if (i % 3 == 0) continue;
                obstacles.add(new Obstacle(i*30,570,10,this));
            }
            //绘制管道
            for (int i = 0; i < 4; i++) {
                obstacles.add(new Obstacle(170+180*i,570,8,this));
                obstacles.add(new Obstacle(190+180*i,570,7,this));
                obstacles.add(new Obstacle(170+180*i,540,6,this));
                obstacles.add(new Obstacle(190+180*i,540,5,this));
                obstacles.add(new Obstacle(170+180*i,510,6,this));
                obstacles.add(new Obstacle(190+180*i,510,5,this));
            }

            //绘制敌人蘑菇
            for (int i = 0; i < 16; i++) {
                enemyList.add(new Enemy(800-50*i,510,true,1,this));
            }

            //绘制敌人食人花
            for (int i = 0; i < 4; i++) {
                enemyList.add(new Enemy(180+180*i,510,2,true,490,540,this));
            }

            for (int i = 30; i < 700; i+=80){
                for (int j = 0;j < 460; j+=70){
                    obstacles.add(new Obstacle(i,j,(int)((Math.random()*10)%2),this));
                }
            }
            obstacles.add(new Obstacle(540,165,11,this));
            obstacles.add(new Obstacle(800,350,11,this));

        }else {
            bg = StaticValue.start;
        }


    }

    public BackGround() {
    }
    public List<Enemy> getEnemyList() {
        return enemyList;
    }

    public int getSort() {
        return sort;
    }

    public BufferedImage getBg() {
        return bg;
    }

    public List<Obstacle> getObstacles() {
        return obstacles;
    }

    public List<Enemy> getDeadEnemy() {
        return deadEnemy;
    }

    public void setDeadEnemy(List<Enemy> deadEnemy) {
        this.deadEnemy = deadEnemy;
    }

    public List<Obstacle> getDeadObstacles() {
        return deadObstacles;
    }

    public void setDeadObstacles(List<Obstacle> deadObstacles) {
        this.deadObstacles = deadObstacles;
    }
}
